home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- # Check whether the coordinates were received.
-
- if ($#ARGV != 0)
- {
- &CgiError("Wrong number of arguments, client may not support ISMAP.");
- }
-
- $query = $ARGV[0];
-
- # Decode the coordinates by splitting the string up into an x part and a y part
- # separated by a comma.
-
- ($x, $y) = split(/,/, $query);
-
- # Test whether the coordinates were received.
-
- if ($y eq '')
- {
- &CgiError("Your client doesn't support image mapping properly.");
- }
-
- # Test if the coordinates are valid. Some browsers actually return negative
- # numbers for coordinates which is a bug in the browser software and we must
- # reject the input. This does not happen very often but it may happen with
- # users having older browsers, so be wary of the browser input.
-
- if ($x < 0 || $y < 0)
- {
- &CgiError("Your browser has returned negative coordinates, which is an
- error. Try upgrading your browser to the latest version.");
- }
-
- # Check the image size encoded in PATH_INFO. First assign the environment
- # variable to a local variable.
-
- $path_info = $ENV{'PATH_INFO'};
-
- # Parse out the cellsize parameter where cellsize equals the size of each cell
- # (width and height) and assign this value to the variable called $cellsize.
-
- $path_info =~ /cellsize=(\d+)/i;
- $cellsize = $1;
-
- # Parse out numcols parameter where numcols equals the number of columns
- # in the image and assign this value to the $numcols variable.
-
- $path_info =~ /numcols=(\d+)/i;
- $numcols = $1;
-
- # Test whether the image size was been defined which means $numcols and $cellsize are
- # both defined and non-zero. Otherwise call the CgiError function to print an error message
- # and exit the program.
-
- unless ($numcols && $cellsize)
- {
- &CgiError("Unable to determine image size from request");
- }
-
- # Print the Mime type to tell your browser to expect HTML output.
-
- print "Content-type: text/html\n\n";
-
- # Print the required HTML tags.
-
- print <<EOH;
- <HTML>
- <HEAD>
- <TITLE>CGI Script How-To: Test Script</TITLE>
- </HEAD>
- <BODY>
- <H1>CGI Script How-to: Test Script</H1>
- EOH
-
- # Calculate the row and column numbers from the coordinates
-
- $col = int($x / $cellsize) + 1;
- $row = int($y / $cellsize) + 1;
-
- # Figure out the cell number given the row and column numbers just computed
- # and the number of columns.
-
- $cellnum = ($row - 1) * $numcols + $col;
-
- # Identify the user's selection with the (x,y) coordinates,
- # row number, column number, and cell number
-
- print "You clicked on the region: <b>x=$x, y=$y</b><P>\n";
- print "This maps to row <b>#$row</b> and column <b>#$col</b><P>\n";
- print "The number of this cell is <b>$cellnum</b>\n";
-
- # Print the final elements of the HTML output and exit
-
- print "</BODY></HTML>\n";
- exit(0);
-
- # CgiError routine displays an HTML page with an error message and exits
-
- sub CgiError
- {
- # Declare local variable to store the argument
- local($msg) = @_;
-
- # Output the HTML mime type. This tells the browser to expect HTML input.
-
- print "Content-type: text/html\n\n";
-
- # Output an HTML document with the error message.
-
- print <<EOH;
- <HTML>
- <HEAD>
- <TITLE>Image Mapping Error</TITLE>
- </HEAD>
- <BODY>
- <H1>Image Mapping Error</H1>
- This CGI program encountered an error:
- <P>
- $msg
- </BODY>
- </HTML>
- EOH
-
- # Exit the program with an non-zero error code.
-
- exit(1);
- }
-
- ##
- ## end of testgrid.pl
- ##
-